This class is meant as an emulation of SCDragSource / SCDragSink / SCDragBoth. last mod: 30-jan-08 sciss
Also refer to JSCView for different behaviour affecting all widgets
| different behaviour | |
| string compilation | the compilation of a string dragged from an external application happens at the end of the dnd gesture ; in cocoa gui, the string is compiled as soon as the mouse is moved over a gui component. |
| extended functionality | |
| string compilation | string compilation can be switched off by calling interpretDroppedStrings_( false ). |
Note: please use the abstraction layer GUI.dragSource / .dragSink / .dragBoth if possible! (see GUI)
Drag+Drop Gadgets ; JSCDragSource can be a source of a drag gesture, JSCDragSink can be a target of a drag gesture. JSCDragBoth combines both a source and a target.
(
var w, f, r;
w = JSCWindow.new;
f = FlowLayout( w.view.bounds );
r = Rect( 0, 0, 150, 30 );
w.view.decorator = f;
JSCStaticText( w, r ).string_( "JSCDragSource" );
x = JSCDragSource( w, r );
f.nextLine;
JSCStaticText( w, r ).string_( "JSCDragSink" );
y = JSCDragSink( w, r );
f.nextLine;
JSCStaticText( w, r ).string_( "JSCDragBoth" );
z = JSCDragBoth( w, r );
w.front;
f.nextLine;
JSCStaticText( w, r ).string_( "Ctrl+Press+Move" );
JSCSlider( w, r );
)
// detect drops
y.action = { arg butt;
("Woooha! We got "++butt.object).postln;
}
// set the object that can be dragged
x.object = "Schnucki 3000";
z.object = "Haschimoto";
currentDrag.asString).currentDrag.currentDrag.currentDrag.
Example: boot the local server, select the following code snipped and drag it onto the drag sink in the window created above:
(
{ Pan2.ar( SinOsc.ar( 220.5, mul: 0.5 ))}.play;
)
Example: drag the following snipped onto the slider:
(
sqrt( 0.5 );
)
This automatic compilation can be switched off, by calling interpretDroppedStrings_( false ) (works with SwingOSC only!):
y.interpretDroppedStrings = false; // now try again to drop a string onto the drag sink!